#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <set>

using namespace std;
using LL = long long;

int n, t;
string s;

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    set<string> st;
    int idx = -1, maxv = -1;

    cin >> n;
    for(int i = 1; i <= n; i ++){
        cin >> s >> t;
        if(st.count(s) == 0){
            if(t > maxv){
                maxv = t;
                idx = i;
            }

            st.insert(s);
        }
    }

    cout << idx << '\n';


    return 0;
}